/************************************************************************
 *	File Description:													*
 *																		*
 *	The singleton interface makes sure that a class derrived from		*
 *	the singleton class can only have one instance.						*
 *																		*
 *  Author:			Jack Kern											*
 *----------------------------------------------------------------------*/

#pragma once


template <class T>
class Singleton
{
public:

	// Inline static function to get the singleton instance
	static T*Inst(void)
	{
		// If no instance is available, then create the instance.
		if( m_instance == 0 )
		{
			m_instance = new T;
		}
		return m_instance;
	}

	// Inline static function to destroy the singleton instance,
	//  this function should only be called at the end of the application.
	static void Destroy(void)
	{
		if( m_instance )
		{
			//delete m_instance;
			m_instance = 0;
		}
	}

protected:
	// Protected constructor / destructor - no objects of type singleton can be create
	//  outside of the singleton class itself. That's why we need a static function
	//  to create the object.
	Singleton() {}
	virtual ~Singleton() { Destroy(); }

private:
	// Private static pointer to object of the type of class being derrived from.
	//  we do this so that the user is not required to cast the pointer returned
	//  from the get instance function.
	static T*	m_instance;

	Singleton(const Singleton& source)
	{
	};

};

// static class member initialization.
template <typename T> T* Singleton<T>::m_instance = 0;


